<template>
  <div class="table-box">
    <el-table :data="tableData" style="width: 100%" @selection-change="handleSelectionChange">
      <el-table-column width="55" type="selection"></el-table-column>
      <el-table-column type="index"></el-table-column>
      <el-table-column prop="reportName" label="报告名称" width="180">
      </el-table-column>
      <el-table-column prop="year" label="所属整改阶段" width="180">
      </el-table-column>
      <el-table-column prop="preparationDepartment" label="编制部门" width="180">
      </el-table-column>
      <el-table-column prop="fileType" label="文件类型" width="180">
      </el-table-column>
      <el-table-column prop="updateTime" label="上传时间" width="180">
      </el-table-column>
      <el-table-column prop="note" label="备注" width="180">
      </el-table-column>
      <el-table-column label="操作" width="180">
        <template slot-scope="scope">
          <el-link @click="Download(scope.row)" type="primary">下载</el-link>
          <el-link @click="delectFile(scope.row)" type="danger">删除</el-link>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { delectReoprt, delectBatchReoprt } from '@/api/report.js'
import bus from '@/config/bus.js'

export default {
  props: ['tableData'],
  data () {
    return { multipleSelection: [] }
  },
  created () {
    bus.$on('batchDelete', () => {
      const batchIds = []
      this.multipleSelection.forEach(item => {
        batchIds.push(item.id)
      })
      const batchIdStr = batchIds.join(',')
      if (batchIdStr) {
        delectBatchReoprt(batchIdStr).then(() => {
          this.$message({
            message: '删除成功！',
            type: 'success'
          })
          this.$emit('updateData')
        })
      }
    })
  },
  methods: {
    Download (row) {
      // console.log(this.baseURL + `/v1/pc/api/file/fileDownload?fileName=${row.reportName}&filePath=${row.filePath}`, '_self')
      window.open(this.baseURL + `/v1/pc/api/file/fileDownload?fileName=${row.reportName}&filePath=${row.filePath}`, '_self')
    },
    delectFile (row) {
      delectReoprt(row.id).then(res => {
        this.$message({
          message: '删除成功！',
          type: 'success'
        })
        this.$emit('updateData')
      })
    },
    handleSelectionChange (val) {
      this.multipleSelection = val
    }
  }
}
</script>

<style scoped>
.table-box {
  display: flex;
  width: 100%;
}
.el-link:first-child {
  margin-right: 12px;
}
.table-box /deep/ .el-table__header,
.table-box /deep/ .el-table__body {
  width: 100% !important;
}
</style>
